package com.heima.schedule.controller;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     */
    @PostMapping("/addTask")
    public ResponseResult<Long> addTask(@RequestBody Task task){
        return ResponseResult.okResult(taskService.addTask(task));
    }
    /**
     * 消费任务
     */
    @PostMapping("/pollTask/{taskTopic}")
    public ResponseResult<List<Task>> pollTask(@PathVariable("taskTopic") Integer taskTopic){
        return ResponseResult.okResult(taskService.pollTask(taskTopic));
    }
}
